package com.mall.b2c.plugin.search;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang.StringUtils;
import org.springframework.util.CollectionUtils;

import com.mall.b2c.domain.goods.GoodsCategoryDomain;
import com.mall.common.hibernate.Finder;
import com.mall.common.plugin.AutoRegisterPlugin;
import com.mall.common.util.UrlUtils;
/**
 * 商品生产厂家筛选器
 * @author wangzx
 *
 */
public class ManufacturerSearchFilter {//extends AutoRegisterPlugin implements IGoodsSearchFilter{

	//@Override
//	public void filter(Finder finder, GoodsCategoryDomain cat, String urlFragment) {
//		if(StringUtils.isNotBlank(urlFragment)){
//			try {
//				String manufacturer = URLDecoder.decode(urlFragment, "utf-8");
//				finder.append( " and g.manufacturer = :manufacturer");
//				finder.setParam("manufacturer", manufacturer);
//			} catch (UnsupportedEncodingException e) {
//			}
//		}
//	}
//
//	//@Override
//	public List<SearchSelector> createSelectorList(GoodsCategoryDomain cat,
//			String url, String urlFragment, Map<String, String> paramMap,
//			String hql, Finder finder) {
//		List<SearchSelector> searchSelectors = new ArrayList<SearchSelector>();
//		/**已选择生产厂家*/
//		if(StringUtils.isNotBlank(urlFragment)) {
//			try {
//				String manufacturer = URLDecoder.decode(urlFragment, "utf-8");
//				SearchSelector searchSelector = new SearchSelector();
//				searchSelector.setName(manufacturer);
//				searchSelector.setSelected(Boolean.TRUE);
//				searchSelector.setUrl(url);
//				searchSelectors.add(searchSelector);
//				return searchSelectors;
//			} catch (UnsupportedEncodingException e) {
//			}
//		}
//		finder.resetHQL("select distinct g.manufacturer from " + hql + " group by g.manufacturer order by count(*) desc");
//		finder.setMaxResults(50);
//		List<String> manufacturerList = finder.findHQLList();
//		if(!CollectionUtils.isEmpty(manufacturerList)) {
//			SearchSelector searchSelector = null;
//			for(String manufacturer : manufacturerList) {
//				searchSelector = new SearchSelector();
//				searchSelector.setName(manufacturer);
//				searchSelector.setUrl(UrlUtils.addUrlParam(url, getFilterId(), manufacturer, false));
//				searchSelector.setSelected(Boolean.FALSE);
//				searchSelectors.add(searchSelector);
//			}
//		}
//		return searchSelectors;
//	}

	/*@Override
	public String getFilterId() {
		return "manufacturer";
	}

	@Override
	public String getSysId() {
		return "manufacturerList";
	}

	@Override
	public String getType() {
		return "goodsSearchFilter";
	}

	@Override
	public String getId() {
		return "manufacturerSearchFilter";
	}

	@Override
	public String getName() {
		return "商品生产厂家筛选器";
	}

	@Override
	public String getVersion() {
		return "1.0";
	}

	@Override
	public String getAuthor() {
		return "wangzx";
	}

	@Override
	public void perform(Object... params) {
		
	}

	@Override
	public void register() {
		
	}*/
}
